﻿<Window x:Class="ThumbGen.MoviePlayer"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ThumbGen"
    Title="Movie Player" WindowState="Maximized" x:Name="TheWindow">
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="BoolVisibilityConverter"/>

        <ControlTemplate x:Key="ImageButton" TargetType="{x:Type Button}">
            <ControlTemplate.Resources>

                <Storyboard x:Key="MouseOver">
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                                               Storyboard.TargetName="contentPresenter" 
                                               Storyboard.TargetProperty="(UIElement.Opacity)">
                        <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
                <Storyboard x:Key="MouseOut">
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                                               Storyboard.TargetName="contentPresenter" 
                                               Storyboard.TargetProperty="(UIElement.Opacity)">
                        <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0.7"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
                <Storyboard x:Key="PressedOn">
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                                               Storyboard.TargetName="contentPresenter" 
                                               Storyboard.TargetProperty="(UIElement.Opacity)">
                        <SplineDoubleKeyFrame KeyTime="00:00:00.0500000" Value="0.3"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
                <Storyboard x:Key="PressedOff">
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                                               Storyboard.TargetName="contentPresenter" 
                                               Storyboard.TargetProperty="(UIElement.Opacity)">
                        <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="0.7"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
            </ControlTemplate.Resources>
            <ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" 
                          Opacity="0.7" x:Name="contentPresenter" Cursor="Hand">
            </ContentPresenter>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" SourceName="contentPresenter" Value="True">
                    <Trigger.EnterActions>
                        <BeginStoryboard Storyboard="{StaticResource MouseOver}"/>
                    </Trigger.EnterActions>
                    <Trigger.ExitActions>
                        <BeginStoryboard x:Name="MouseOut_BeginStoryboard" Storyboard="{StaticResource MouseOut}"/>
                    </Trigger.ExitActions>
                </Trigger>
                <Trigger Property="IsPressed"  Value="True">
                    <Trigger.EnterActions>
                        <BeginStoryboard x:Name="PressedOn_BeginStoryboard" Storyboard="{StaticResource PressedOn}"/>
                    </Trigger.EnterActions>
                    <Trigger.ExitActions>
                        <BeginStoryboard x:Name="PressedOff_BeginStoryboard" Storyboard="{StaticResource PressedOff}"/>
                    </Trigger.ExitActions>
                    <Setter Property="Opacity" TargetName="contentPresenter" Value="1"/>
                </Trigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Opacity" TargetName="contentPresenter" Value="0.2"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Window.Resources>
    <Grid x:Name="MainGrid" Background="Black">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <StackPanel Orientation="Vertical">
                <StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
                    <!-- Play button. -->
                    <Button Click="Button_Click" Template="{StaticResource ImageButton}" ToolTip="Play video">
                        <Image Source="/images/videoplayer/play.png"/>
                    </Button>

                    <!-- Pause button. -->
                    <Button Click="Button_Click_2" Template="{StaticResource ImageButton}" ToolTip="Pause video">
                        <Image Source="/images/videoplayer/pause.png"/>
                    </Button>

                    <!-- Stop button. -->
                    <Button Click="Button_Click_3" Template="{StaticResource ImageButton}" ToolTip="Stop video">
                        <Image Source="/images/videoplayer/stop.png"/>
                    </Button>

                    <Button Margin="10 0 0 0" Click="Button_Click_4" Template="{StaticResource ImageButton}" ToolTip="Take a snapshot now">
                        <Image Source="/images/videoplayer/record.png"/>
                    </Button>

                    <TextBlock Margin="5 0 5 0" Text="Zoom:" Foreground="White" VerticalAlignment="Center"/>

                    <Slider Name="ZoomSlider" Margin="5" Height="16" TickPlacement="BottomRight" ToolTip="Zoom factor" Width="100"
                            ValueChanged="ZoomSlider_ValueChanged" Minimum="0.1" Maximum="5" Value="1" SmallChange="0.05"
                            VerticalAlignment="Center"/>
                    <TextBlock VerticalAlignment="Center" Foreground="White" Margin="3 0 0 0"
                               Text="{Binding ElementName=ZoomSlider,Path=Value,StringFormat= (\{0:0.00\}x)}"/>

                    <!-- Volume slider. This slider allows a Volume range between 0 and 1. -->
                    <Image Source="/images/videoplayer/volume.png" Margin="15 0 0 0" Visibility="Collapsed"/>
                    <Slider Name="volumeSlider" VerticalAlignment="Center" ValueChanged="ChangeMediaVolume" ToolTip="Adjust sound volume"
                            Minimum="0" Maximum="1" Value="0.500" Width="70" Height="16" TickPlacement="BottomRight"
                            Visibility="Collapsed"/>

                    <CheckBox x:Name="cbUseCropper" IsChecked="{Binding Path=UseCropper,Mode=TwoWay}" FontWeight="Bold" Margin="10 0 0 0" 
                              Content="Use Cropper" Foreground="White" VerticalAlignment="Center"
                              ToolTip="Use the cropper tool to make snapshots instead of capturing the full size movie screen"/>

                </StackPanel>
                <Slider Name="timelineSlider" Margin="5" 
                        ValueChanged="SeekToMediaPosition"
                        Height="16" TickPlacement="BottomRight" 
                        ToolTip="Seek"/>
                <TextBlock Foreground="White" Text="{Binding ElementName=TheWindow,Path=TimeInformation}" Margin="10 0 10 0"
                               HorizontalAlignment="Right" VerticalAlignment="Center"/>

                <!--To interactively stop, pause, and play the media, the LoadedBehavior property of the MediaElement must be set to "Manual".-->
                <Canvas>
                    <ContentControl Name="ThePlayer" HorizontalAlignment="Center">
                        <MediaElement Name="myMediaElement" HorizontalAlignment="Center"
                          LoadedBehavior="Manual" UnloadedBehavior="Stop" Stretch="Uniform" 
                          MediaOpened="Element_MediaOpened" MediaEnded="Element_MediaEnded" MediaFailed="myMediaElement_MediaFailed"/>
                    </ContentControl>
                    <ContentControl x:Name="TheCropper" local:DraggableExtender.IsWatermark="False"  local:DraggableExtender.CanDrag="True"
                                    Visibility="{Binding Path=UseCropper, Converter={StaticResource BoolVisibilityConverter}}"
                                    Cursor="Hand">
                        <Grid>
                            <Rectangle x:Name="TheCropperRect" Stroke="Blue" StrokeThickness="3" Cursor="Hand" Fill="AliceBlue" Opacity="0.2"/>
                            <TextBlock Text="The Cropper Tool" Foreground="Navy" Margin="10"/>
                        </Grid>
                    </ContentControl>
                </Canvas>

            </StackPanel>
            <Button Grid.Row="1" Margin="10" Width="75" HorizontalAlignment="Right" 
                    Content="OK" x:Name="OKButton" Click="OKButton_Click" IsDefault="True" IsCancel="True"/>
        </Grid>
    </Grid>
</Window>